import request from '@/utils/request'
import store from '@/store'
// 查询VipRecharge列表
export function listVipRecharge(query) {
    return request({
        url: '/api/v1/vipRechargeList',
        method: 'get',
        params: query
    }).then(function (res) {
        
        let skuDurationOptions = store.getters.parameter.sys_sku_duration; 
        res.data.list.forEach((item, index) => {
            // console.log(item)
            for (let key in item) {
                // console.log(key + '---' + item[key])
                if (key == "vipDuration") { 
                    item[key] = getDictLabelByValue(item[key], skuDurationOptions)
                }
                 
            }
             
            res.data.list[index] = item
        });
        // console.log(res.data.list)
        return res;
    
    })
}


function getDictLabelByValue(value,dict_list){
    let dictLabel="";
    dict_list.forEach((_item,index)=>{
        if(_item.dictValue==value){
            dictLabel= _item.dictLabel
        }
    })
    return dictLabel;
}
// 查询VipRecharge详细
export function getVipRecharge(rechargeId) {
    return request({
        url: '/api/v1/vipRecharge/' + rechargeId,
        method: 'get'
    })
}


// 新增VipRecharge
export function addVipRecharge(data) {
    return request({
        url: '/api/v1/vipRecharge',
        method: 'post',
        data: data
    })
}

// 修改VipRecharge
export function updateVipRecharge(data) {
    return request({
        url: '/api/v1/vipRecharge',
        method: 'put',
        data: data
    })
}

// 删除VipRecharge
export function delVipRecharge(rechargeId) {
    return request({
        url: '/api/v1/vipRecharge/' + rechargeId,
        method: 'delete'
    })
}
